;(function (win) {
    var doc = win.document;
    var docEl = doc.documentElement;
    var tid;
    function getStyle(dom, attr) {
        if (window.getComputedStyle) {
            return window.getComputedStyle(dom, null)[attr];
        } else {
            return dom.currentStyle[attr];
        }
    }
    function fixFontSize(width, rem, html) {
        var body = doc.getElementsByTagName('body')[0];
        body.style.width = '7.5rem';
        var scale = 1;
        var bodyWidth = parseInt(getStyle(body, 'width'));
        if (bodyWidth != width) {
            scale = width / bodyWidth;
            rem = rem * scale;
            docEl.style.fontSize = rem + 'px';
        }
        body.style.width = '100%';
    }
    function refreshRem() {
        var html = document.getElementsByTagName('html')[0];
        var width = parseInt(getStyle(html, 'width'));
        /*if (width > 768) {
         width = 768;
         }*/
        var rem = width / 7.5;
        docEl.style.fontSize = rem + 'px';
        fixFontSize(width, rem);
    }

    win.addEventListener('resize', function () {
        clearTimeout(tid);
        tid = setTimeout(refreshRem, 300);
    }, false);

    win.addEventListener('pageshow', function (e) {
        if (e.persisted) {
            clearTimeout(tid);
            tid = setTimeout(refreshRem, 300);
        }
    }, false);
    refreshRem();
})(window);